package pl.kosmowska.ewelina.client.app.activity.places;

import pl.kosmowska.ewelina.client.app.requestfactory.dto.StockDataProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;

public class StockEditPlace extends Place {
	  

	  @Prefix("DodajZmienInwestycjeGieldowa")
	  public static class Tokenizer implements PlaceTokenizer<StockEditPlace> {

	    private RequestFactory requestFactory;
	    
	    public Tokenizer(RequestFactory requestFactory) {
	      this.requestFactory = requestFactory;
	    }
	    	    
	    @Override
	    public String getToken(StockEditPlace place) {
	      String s = "";
	      if (place.getStockDataId() != null) {
	        s = requestFactory.getHistoryToken(place.getStockDataId());
	      } else if (place.getStockData() != null) {
	        s = requestFactory.getHistoryToken(place.getStockData().stableId());
	      } else {
	        s = "new"; 
	      }
	      return s;
	    }

	    /**
	     * from - url activated
	     */
	    @Override
	    public StockEditPlace getPlace(String token) {
	      EntityProxyId<StockDataProxy> StockDataId = null;
	      if (token == null || token.trim().length() == 0 || token.equals("new") == true) {
	        // new
	      } else {
	        StockDataId = requestFactory.<StockDataProxy> getProxyId(token);
	      }
	      return new StockEditPlace(StockDataId);
	    }

	  }
	     
	  /**
	   * from app place move
	   */
	  private StockDataProxy stockData;
	  
	  /**
	   * from url place move
	   */
	  private EntityProxyId<StockDataProxy> stockDataId;
	  
	  /**
	   * constructor - from app new place
	   */
	  public StockEditPlace() {
	    this.stockDataId = null;
	    this.stockData = null;
	  }

	  
	  
	  /**
	   * constructor - from app place move
	   * @param walletData
	   */
	  public StockEditPlace(StockDataProxy StockData) {
	    this.stockDataId = null;
	    this.stockData = StockData;
	  }

	  /**
	   * constructor - from url move
	   * @param walletDataId
	   */
	  public StockEditPlace(EntityProxyId<StockDataProxy> StockDataId) {
	    this.stockDataId = StockDataId;
	  }
	  

	  public EntityProxyId<StockDataProxy> getStockDataId() {
		    return stockDataId;
		  }
	  
	  public StockDataProxy getStockData() {
		    return stockData;
		  }
	 
	}


